{
  LW Node Editor -- LightWave Node Editor Functions.

  This global provides access to a user interface for editing nodes.

  Based on lwnodeeditor.h which is:
  Copyright 2005, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}
unit LW_NodeEditor;

{$mode objfpc}{$H+}

interface

uses
  LW_Types  ,
  LW_IO     ,
  LW_Envel  ,
  LW_Server ,
  LW_XPanel ,
  LW_Render ,
  LW_Nodes  ;

const
  LWNODEEDITORFUNCS_GLOBAL = 'NodeEditorFuncs 3' ;


type
  // Autosize function, which is used when calling NodeAutosize, from LWNodeUtilityFuncs ( lwnodes.h )
  TNodeAutoSizeFunc = procedure
                     (       NodeEditorID : PNodeEditor   ;
                             UserData     : Pointer       ;
                             SclPos       : array {[0..2 , 0..1]} of Double ) ;
  // Update function, which is called when "Instance Update" global function
  //  is called with LWNODE_HCLASS.
  TNodeEditorUpdateFunc = procedure
                         (       NodeEditorID : PNodeEditor   ) ;

  PLWRootNode = ^TLWRootNode ;
  TLWRootNode = record
    // Init for the root node.
    Init      : function
                (       NodeEditorID : PNodeEditor   ;
                        Mode         : Integer       ) : PLWError ;
    // Newtime for the root node.
    NewTime   : function
                (       NodeEditorID : PNodeEditor   ;
                        Frame        : TLWFrame      ;
                        Time         : TLWTime       ) : PLWError ;
    // Cleanup for the root node.
    Cleanup   : procedure
                (       NodeEditorID : PNodeEditor   ) ;
    // Interface panel function, for the embedded panels.
    RootPanel : function
                (       NodeEditorID : PNodeEditor   ) : PLWXPanel;
    // Options is called when no panel is defined for the root node.
    RootOptions : function
                (       NodeEditorID : PNodeEditor   ) : PLWError ;
    // Preview function to draw the preview sphere for the root node.
    RootPreview : procedure
                 (       Editor : PNodeEditor          ;
                         NodeAc : PLWNodalAccess       ;
                         PColor : TLWDVector           ) ;
    // Custom preview function, for doing custom previews for the root node.
    RootCustomPreview : procedure
                        (       Editor : PNodeEditor          ;
                                Width  ,
                                Height : Integer              ) ;
  end;

  PLWNodeEditorFuncs = ^TLWNodeEditorFuncs ;
  TLWNodeEditorFuncs = record
    // Create a node editor ID.
    Create           : function
                       ( const RootName      :  Pchar       ;
                         const PanelTitle    :  PChar       ;
                               RootNodefuncs :  PLWRootNode ;
                               UserData      :  Pointer     ) : PNodeEditor ;
    // Destroy a node editor ID.
    Destroy          : procedure
                       (        NodeEditorID : PNodeEditor  ) ;
    // Rename the editor. It is essentially the title for the editor window.
    Rename           : procedure
                       (        NewName      : Pchar        ;
                                NodeEditorID : PNodeEditor  ) ;
    // Set the update function for the editor.
    SetUpdateFunc    : procedure
                       (        NodeEditorID : PNodeEditor  ;
                                UpdateFunc   : TNodeEditorUpdateFunc ) ;
    // Copy the node editor data.
    Copy             : function
                       (        ToNodeEdID   : PNodeEditor  ;
                                FromNodeEdID : PNodeEditor  ) : PLWError    ;
    // Save the node editor data.
    Save             : function
                       (        NodeEditorID : PNodeEditor  ;
                         const  SaveState    : PLWSaveState ) : PLWError    ;
    // Load the node editor data.
    Load             : function
                       (        NodeEditorID : PNodeEditor  ;
                         const  LoadState    : PLWLoadState ) : PLWError    ;
    // init, newTime, and cleanup are the same as in LWRenderFuncs.
    // Init needs to be called before any attempt to evaluate the inputs from the destination node.
    // Cleanup needs to be called after rendering is finished.
    Init             : function
                       (        NodeEditorID : PNodeEditor  ;
                                Mode         : Integer      ) : PLWError    ;
    NewTime          : function
                       (        NodeEditorID : PNodeEditor  ;
                                Frame        : TLWFrame     ;
                                Time         : TLWTime      ) : PLWError    ;
    Cleanup          : procedure
                       (        NodeEditorID : PNodeEditor  ) ;
    // Add an input to the root node.
    AddInput         : function
                       (        NodeEditorID   : PNodeEditor  ;
                                // Originally enum ConnectionType
                                ConnectionType : Integer      ;
                         const  Name           : PChar        ;
                                InputEventFunc : TNodeInputEvent  ) : PLWError    ;
    // Remove an input from the root node.
    RemInput         : procedure
                       (        NodeEditorID : PNodeEditor    ;
                                NodeInputID  : PNodeInput     ) ;
    // Set the envelope group for the editor. All node envelope groups are parented into this group.
    SetEnvGroup      : procedure
                       (        NodeEditorID : PNodeEditor    ;
                                ChanGroupID  : PLWChanGroup   ) ;
    // Set the autosize function for the editor.
    SetAutosize      : procedure
                       (        NodeEditorID   : PNodeEditor        ;
                                AutoSizeFunc   : TNodeAutoSizeFunc  ) ;
    // Set the userdata for this editor.
    SetUserData      : procedure
                       (        NodeEditorID   : PNodeEditor  ;
                                UserData       : Pointer      ) ;
    // Get the userdata from this editor.
    GetUserData      : function
                       (        NodeEditorID   : PNodeEditor  ) : Pointer ;

    // Returns the number of nodes in this editor.
    NumberOfNodes    : function
                       (        NodeEditorID   : PNodeEditor  ) : Integer ;
    // These return an NodeInputID from the destination node,
    // which can be used to evaluate an input from the destination,
    // using the NodeInputFuncs global evaluate.
    GetInputByName   : function
                       (        NodeEditorID   : PNodeEditor  ;
                         const  InputName      : PChar        ) : PNodeInput ;
    GetInputByIndex  : function
                       (        NodeEditorID   : PNodeEditor  ;
                                Index          : Integer      ) : PNodeInput ;

    // Get the state. Enabled/Disabled.
    GetState         : function
                       (        NodeEditorID   : PNodeEditor  ) : UInt16     ;

    // Set the state.
    SetState         : procedure
                       (        NodeEditorID   : PNodeEditor  ;
                                State          : UInt16       ) ;
    // Open the editor window.
    OpenNodeEditor   : function
                       (        NodeEditorID   : PNodeEditor  ) : Integer    ;
    // Is the node editor open, and set to this NodeEditorID?
    IsOpenNodeEditor : function
                       (        NodeEditorID   : PNodeEditor  ) : Integer    ;

    // Get an NodeID for the root node;
    GetRootNodeID    : function
                       (        NodeEditorID   : PNodeEditor  ) : PNode      ;
    // Create a connection from the output to the input.
    Connect          : function
                       (        OutputID       : PNodeOutput  ;
                                InputID        : PNodeInput   ) : PLWError   ;
    // Add a node to the flow using a server name.
    AddNode          : function
                       (        NodeEditorID   : PNodeEditor  ;
                         const  ServerName     : PChar        ) : PNode      ;
    // Destroy a node.
    DestroyNode      : procedure
                       (        NodeEditorID   : PNodeEditor  ) ;
    // Set the X and Y coordinates for the node.
    SetXY            : procedure
                       (        NodeEditorID   : PNodeEditor  ;
                                X              ,
                                Y              : Integer      ) ;
    // Set the context for the Node Editor
    SetContext       : procedure
                       (        NodeEditorID   : PNodeEditor  ;
                         const  Context        : PChar        ) ;
    // Returns the used items for the whole Node Editor and it's nodes.
    UsedItems        : function
                       (        NodeEditorID   : PNodeEditor  ) : PLWItem    ; // const
  end;

implementation

end.

